/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
/*
    |dummy -> 1 -> 2 |-> 3 -> 4
     pre     cur  Next

    dummy ->| 1 -> 2 -> 3 |-> 4
            pre  cur   Next
*/
class code1 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0,head);
        ListNode prev = dummy;
        ListNode cur = head;

        while(cur != null && cur.next != null) {
            ListNode Next = cur.next;

            //开始交换(cur和Next)
            cur.next = Next.next;
            Next.next = cur;
            prev.next = Next;

            //迭代
            prev = cur;
            cur = cur.next;
        }
        return dummy.next;
    }
}